package com.ctjsoft.datacollection.core.execute;

import org.pentaho.di.core.Result;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogLevel;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransExecutionConfiguration;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.cluster.TransSplitter;

import java.util.Map;

public class TransClusterExecute {

    String executeTrans(TransMeta tm, Map<String, String> params, LogLevel logLevel) throws KettleException {
        TransExecutionConfiguration configuration = new TransExecutionConfiguration();
        configuration.setRunConfiguration("集群");
        configuration.setExecutingClustered(true);
        configuration.setLogLevel(logLevel);
        configuration.setSetAppendLogfile(true);
        configuration.setLogRemoteExecutionLocally(false);
        configuration.setParams(params);
        configuration.setSafeModeEnabled(false);
        configuration.setClusterPosting(true);
        configuration.setClusterPreparing(true);
        configuration.setClusterStarting(true);
        TransSplitter transSplitter = Trans.executeClustered(tm, configuration);

        Result clusteredTransformationResult = Trans.getClusteredTransformationResult(
                transSplitter.getMasterServer().getLogChannel(), transSplitter, null);

        boolean result = clusteredTransformationResult.getResult();
        return "";

    }
}
